//
//  searchTableViewCell.m
//  lmq
//
//  Created by 千翼网络科技 on 2017/3/23.
//  Copyright © 2017年 yuanxin. All rights reserved.
//

#import "searchTableViewCell.h"
#import "configddd.h"
#import <Masonry/Masonry.h>

@implementation searchTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:@"identifier"]) {
        
        [self initView];
    }
    return self;
}

#pragma mark ---------------- init -----------------

- (void)initView{
    
    self.backgroundColor = getColor(@"ffffff");

    _nameLable = [[UILabel alloc]init];
    _nameLable.text = @"商品1";
    _nameLable.textColor = getColor(@"757575");
    _nameLable.textAlignment = NSTextAlignmentLeft;
    _nameLable.font = get4sFont(12);
    [self addSubview:_nameLable];
    [_nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).with.offset(screenScale(22));
        make.left.mas_equalTo(self).with.offset(screenScale(22));
        
        make.height.mas_equalTo(screenScale(26));
    }];
    
    
    _deleteBtn = [[UIButton alloc]init];
    _deleteBtn.titleLabel.font = get4sFont(12);
    [_deleteBtn setTitle:@"x" forState:UIControlStateNormal];
    [_deleteBtn setTitleColor:getColor(@"757575") forState:UIControlStateNormal];
    [_deleteBtn addTarget:self action:@selector(deleteBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_deleteBtn];
    [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(0);
        make.right.mas_equalTo(self).with.offset(screenScale(screenScale(-22)));
        make.width.mas_equalTo(screenScale(66));
        make.height.mas_equalTo(screenScale(66));
    }];
    
    _threadView = [[UIView alloc]init];
    _threadView.backgroundColor = getColor(@"e6e6e6");
    [self addSubview:_threadView];
    [_threadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self).with.offset(screenScale(-2));
        make.left.mas_equalTo(self).with.offset(0);
        make.width.mas_equalTo(scrWidth());
        make.height.mas_equalTo(screenScale(2));
    }];
}

#pragma mark ------------------- click -----------------

- (void)deleteBtnClick{
    
    NSMutableArray *arr = [[NSMutableArray alloc]initWithArray:[PublicFunction getConfigWithKey:@"historyRecord"]];
    for (int i = 0; i < arr.count; i ++) {
        
        if ([arr[i] isEqualToString:_nameLable.text]) {
            
            [arr removeObject:_nameLable.text];
        }
    }
    [PublicFunction saveConfig:arr forKey:@"historyRecord"];
    
    NSDictionary *dict =[[NSDictionary alloc]initWithObjectsAndKeys:@"yes",@"selected", nil];
    NSNotification *notification =[NSNotification notificationWithName:@"reloadTableview" object:nil userInfo:dict];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}

@end
